home *** CD-ROM | disk | FTP | other *** search
/ The Business Master (3rd Edition) / The Business Master (3rd Edition).iso / files / business / stata3 / anova.tut next >
Encoding:
Text File  |  1988-08-29  |  10.4 KB  |  296 lines

  1. set output error
  2. set display page 23
  3. set more 1
  4. #delimit ;
  5.  
  6. di _n(5) in wh
  7. "  ___  ____  ____  ____  ____ tm" _n
  8. " /__    /   ____/   /   ____/" _n
  9. "___/   /   /___/   /   /___/    Estimating ANOVA and ANOCOVA Models" _n
  10. "-------------------------------------------------------------------" _n(2) ;
  11.  
  12. di in gr
  13. "This tutorial provides an overview of the Stata commands for estimating" _n
  14. "analysis-of-variance (ANOVA) and analysis-of-covariance (ANOCOVA) models." _n
  15. "The commands we discuss are:" _n(2)
  16. _col(20) in wh "oneway     anova     test" _n(2)
  17. in gr
  18. "We will use a data set that records the changes in systolic blood pressure" _n
  19. "for 58 patients.  Each patient suffered from one of three diseases, and each"
  20. _n
  21. "was given one of four drugs." _n(6) ;
  22.  
  23.  
  24. #delimit cr
  25. mac def path
  26. capture run nullfile.tut
  27. if _rc {
  28.     mac def path "\stata\"
  29.     capture run %path`nullfile.tut
  30.     if _rc {
  31.         mac def path "/usr/stata/"
  32.         capture run %path`nullfile.tut
  33.         if _rc {
  34.             #delimit ;
  35.             di in red
  36. "I cannot find the other tutorial files.  I have looked in the current" _n
  37. "directory and in \stata (DOS) or /usr/stata (Unix).  Is Stata installed" _n
  38. "correctly?" _n(2)
  39. "In any case, I cannot run the tutorial." ;
  40.             #delimit cr
  41.             exit
  42.         }
  43.     }
  44. }
  45. macro define F5 "do %path`contents.tut;"
  46. macro define F6 "do %path`anova.tut;"
  47. #delimit ;
  48.  
  49. di in wh ". use %path`systolic, clear" ;
  50. noisily use %path`systolic, clear ;
  51. set more 0 ; more ; set more 1 ;
  52. di _n in wh ". describe" ;
  53. noisily describe ;
  54. di _n ". list in 1/7" ;
  55. noisily list in 1/7 ;
  56. set more 0 ; more ; set more 1 ;
  57.  
  58. di _n(2) in wh _dup(79) "-" _n in gr
  59. "Stata's '"
  60. in wh "oneway"
  61. in gr "' command estimates one-way ANOVA models and has options for" _n
  62. "performing several multiple-comparison (means separation) tests.  Below," _n
  63. "we'll estimate a one-way model with the change in blood pressure as the" _n
  64. "response variable and the drug given each patient as the control." _n(2)
  65. "The syntax for estimating a one-way model is" _n(2)
  66. _col(16) in wh "oneway" in gr " response control" _n(2)
  67. "where 'response' is the name of the response variable and 'control' is the" _n
  68. "name of the control variable." _n
  69. in wh _dup(79) "-" _n(11)
  70. ". oneway systolic drug" ;
  71. set more 0 ; more ; set more 1 ;
  72. noisily oneway systolic drug ;
  73.  
  74. di _n(2) in wh _dup(79) "-" _n in gr
  75. "The reported between-group variance suggests that changes in systolic blood" _n
  76. "pressure are significantly different among patients receiving different med-"
  77. _n
  78. "ications." _n(2)
  79. "Stata will also report the mean value of the response variable for each level"
  80. _n
  81. "of the control if we add the '" in wh "tabulate" in gr "' option:" _n
  82. in wh _dup(79) "-" _n(2)
  83. ". oneway systolic drug, tabulate" ;
  84. set more 0 ; more ; set more 1 ;
  85. noisily oneway systolic drug, tabulate ;
  86. di _n ; set more 0 ; more ; set more 1 ;
  87.  
  88.  
  89. di _n(2) in wh _dup(79) "-" _n in gr
  90. "Stata will perform the Bonferroni, Scheffe, and Sidak multiple-comparison" _n
  91. "tests on one-way ANOVA models.  The tests are requested by adding an option" _n
  92. "to the "
  93. in wh "oneway"
  94. in gr " command.  For instance, if we wanted to estimate our model and" _n
  95. "add the Bonferroni test, we type:" _n
  96. in wh _dup(79) "-" _n(17)
  97. ". oneway systolic drug, bonferroni" ;
  98. set more 0 ; more ; set more 1 ;
  99. noisily oneway systolic drug, bonferroni ;
  100. set more 0 ; more ; set more 1 ;
  101.  
  102. di _n(2) in wh _dup(79) "-" _n in gr
  103. "Stata's "
  104. in wh "anova"
  105. in gr " command performs N-way ANOVA and ANOCOVA estimation.  It" _n
  106. "will estimate one-way ANOVA, too, but "
  107. in wh "oneway" in gr " is faster." _n(2)
  108. in wh
  109. "anova"
  110. in gr " is like all of Stata's estimation commands; after typing '"
  111. in wh "anova" in gr "', you" _n
  112. "specify the response variable and the control variables.  Control variables" _n
  113. "may be interacted using the standard '"
  114. in wh "*" in gr "' notation.  For example:" _n ;
  115.  
  116. di
  117. in wh _col(15) "anova y a" in gr _col(37) "estimates a one-way layout" _n
  118. in wh _col(15) "anova y a b" in gr _col(37) "estimates a two-way layout" _n
  119. in wh _col(15) "anova y a b a*b" in gr _col(37)
  120. "estimates a two-way factorial layout" _n(2)
  121. "You can write more complicated layouts, too.  Let's use our blood pressure" _n
  122. "data to illustrate these features.  First, we'll specify a two-way model with"
  123. _n
  124. "no interaction.  We will use blood pressure as the response variable and drug"
  125. _n
  126. "and disease as the controls." _n
  127. in wh _dup(79) "-" _n(7)
  128. ". anova systolic drug disease" ;
  129. set more 0 ; more ; set more 1 ;
  130. noisily anova systolic drug disease ;
  131.  
  132. di _n(2) in wh _dup(79) "-" _n in gr
  133. "The sums of squares used in the test are partial sums of squares.  If we" _n
  134. "wanted to estimate the model sequentially with disease first, we would type:"
  135. _n
  136. in wh _dup(79) "-" _n(2)
  137. ". anova systolic disease drug, sequential" ;
  138. set more 0 ; more ; set more 1 ;
  139. noisily anova systolic disease drug, sequential ;
  140.  
  141. di _n(2) in wh _dup(79) "-" _n in gr
  142. "Let's return to ANOVA models using partial sums of squares.  If we want to" _n
  143. "include the interaction of drug and disease, we type:" _n
  144. in wh _dup(79) "-" _n(2)
  145. ". anova systolic drug disease drug*disease" ;
  146. set more 0 ; more ; set more 1 ;
  147. noisily anova systolic drug disease drug*disease ;
  148.  
  149. di _n(2) in wh _dup(79) "-" _n in gr
  150. "We could have typed '"
  151. in wh "disease*drug" in gr "' instead of '"
  152. in wh "drug*disease" in gr "' and, since we are"
  153. _n
  154. "using partial sums of squares, terms can be in any order." _n
  155. in wh _dup(79) "-" _n ;
  156. set more 0 ; more ; set more 1 ;
  157.  
  158. di _n(2) in wh _dup(79) "-" _n in gr
  159. "After estimating an ANOVA model, you can specify various tests.  We just esti-"
  160. _n
  161. "mated a model of systolic on drug, disease, and drug*disease.  The F-test" _n
  162. "on drug was 9.05.  We can obtain exactly the same result, the direct effect of"
  163. _n
  164. "drug, by typing:" _n
  165. in wh _dup(79) "-" _n(2)
  166. ". test drug" ;
  167. noisily test drug ;
  168.  
  169. di _n(4) in wh _dup(79) "-" _n in gr
  170. "We can test more complicated hypotheses as well.  For instance, if we type" _n
  171. "'"
  172. in wh "test drug drug*disease"
  173. in gr "', we test the effect of drug nested within disease."
  174. _n
  175. in wh _dup(79) "-" _n(2)
  176. ". test drug drug*disease" ;
  177. set more 0 ; more ; set more 1 ;
  178. noisily test drug drug*disease ;
  179.  
  180. di _n(2) in wh _dup(79) "-" _n in gr
  181. "Unless you specify otherwise, Stata uses the residual mean square as the error"
  182. _n
  183. "term.  You may, however, request F-tests using other effects as the error "
  184. "term." _n
  185. in wh _dup(79) "-" _n(2)
  186. ". test drug, error(drug*disease)" ;
  187. noisily test drug, error(drug*disease) ;
  188. set more 0 ; more ; set more 1 ;
  189.  
  190.  
  191. di _n(2) in wh _dup(79) "-" _n in gr
  192. "You can obtain the underlying regression model as well as the ANOVA table." _n
  193. "Let's illustrate with a simple two-way layout:" _n
  194. in wh _dup(79) "-" _n(2)
  195. ". anova systolic drug disease" ;
  196. noisily anova systolic drug disease ;
  197.  
  198. di _n in wh _dup(79) "-" _n in gr
  199. "We can now obtain the regression by typing '"
  200. in wh "regress" in gr "':" _n
  201. in wh _dup(79) "-" ;
  202. set more 0 ; more ; set more 1 ;
  203. di _n in wh ". regress" ;
  204. noisily regress ;
  205. set more 0 ; more ; set more 1 ;
  206.  
  207. di _n(10) in wh _dup(79) "-" _n in gr
  208. "We have illustrated how the "
  209. in wh "test" in gr " command can be used to test effects.  "
  210. in wh "test" _n in gr
  211. "can also be used to test hypotheses about the individual coefficients." _n(2)
  212. "For example, we'll test whether the coefficient on the second drug is sta-" _n
  213. "tistically different than that on the third drug:" _n
  214. in wh _dup(79) "-" _n(3)
  215. ". test _coef[ drug[2] ] = _coef[ drug[3] ]" ;
  216. noisily test _coef[ drug[2] ] = _coef[ drug[3] ] ;
  217. set more 0 ; more ; set more 1 ;
  218.  
  219. di _n(4) in wh _dup(79) "-" _n
  220. "test" in gr
  221. " has the ability to perform algebra, so that you can specify tests the" _n
  222. "way you want.  Here's a simple, but crazy test:" _n
  223. in wh _dup(79) "-" _n(3)
  224. ". test _coef[disease[2]] + 3*_coef[disease[3]] = 6 + _coef[disease[3]]" ;
  225. noisily test _coef[disease[2]] + 3*_coef[disease[3]] = 6 + _coef[disease[3]] ;
  226. set more 0 ; more ; set more 1 ;
  227.  
  228. di _n(9) in wh _dup(79) "-" _n in gr
  229. "Stata even has the capability to show you the symbolic form of the estimable"
  230. _n
  231. "functions and the symbolic form for a particular test.  We'll illustrate by" _n
  232. "returning to our two-way factorial model.  We must reestimate, but to save"
  233. _n
  234. "space we'll precede the command by '"
  235. in wh "quietly" in gr "' so that the ANOVA table does not" _n
  236. "appear." _n ;
  237.  
  238. di in gr
  239. "On the next screen, we show the symbolic form of the estimable functions by" _n
  240. "typing '" in wh "test, symbolic" in gr "'." _n(2)
  241. "On the screen after that, we show the symbolic form of the test of drug by" _n
  242. "typing '" in wh "test drug, symbolic" in gr "'" _n
  243. in wh _dup(79) "-" _n(6)
  244. ". quietly anova systolic drug disease drug*disease" ;
  245. anova systolic drug disease drug*disease, nooutput ;
  246. di _n in wh ". test, symbolic" ;
  247. set more 0 ; more ; set more 1 ;
  248. noisily test, symbolic ;
  249. set more 0 ; more ; set more 1 ;
  250. di in wh _n ". test drug, symbolic" ;
  251. noisily test drug, symbolic ;
  252. set more 0 ; more ; set more 1 ;
  253.  
  254.  
  255. di _n(2) in wh _dup(79) "-" _n in gr
  256. "The "
  257. in wh "anova"
  258. in gr " command can also estimate analysis-of-covariance (ANOCOVA) models," _n
  259. "just tell Stata which variables are continuous." _n(2)
  260. "We have another variation on our blood pressure data that contains the age" _n
  261. "of the patient as well as the increase in systolic blood pressure, drug," _n
  262. "and disease:" _n
  263. in wh _dup(79) "-" _n(2)
  264. ". use %path`sysage, clear" ;
  265. noisily use %path`sysage, clear ;
  266. di _n in wh ". summarize age" ;
  267. noisily summarize age ;
  268.  
  269. di _n in wh _dup(79) "-" _n in gr
  270. "Let's estimate systolic as a function of drug, disease, age, and disease" _n
  271. "interacted with age:" _n
  272. in wh _dup(79) "-" _n(2)
  273. ". anova systolic drug disease age disease*age, continuous(age)" ;
  274. set more 0 ; more ; set more 1 ;
  275. noisily anova systolic drug disease age disease*age, continuous(age) ;
  276. di _n ; set more 0 ; more ; set more 1 ;
  277.  
  278. macro define F6 "do %path`probit.tut;"  ;
  279.  
  280. di _n(4) in white
  281. "Demonstration ends" _n
  282. "------------------" _n ;
  283.  
  284. di in green
  285. "That concludes our short demonstration, but there's much more.  We now return"
  286. _n
  287. "control to you.  Some suggestions:" _n ;
  288.  
  289. di in green
  290. "If you ..." _col(34) "Then we will show you ..." _n
  291. "    Press " in white "F5" in green _col(38) "a table of tutorial contents" _n
  292. "    Press " in white "F6" in green _col(38) "the next tutorial, "
  293. in white "probit.tut" _n ;
  294.  
  295. run %path`tobuy.tut ;
  296.